﻿/*
 * 
 * Copyright (c) 2008-2010 Lu Aye Oo
 * 
 * @author 		Lu Aye Oo
 * 
 * http://code.google.com/p/flash-console/
 * 
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 * 
 */
package
{
	import com.junkbyte.console.CLog;
	import com.junkbyte.console.Cc;

	import flash.display.*;
	import flash.geom.Rectangle;

	[SWF(width='700',height='300',backgroundColor='0xFFFFFF',frameRate='30')]
	// Might want to add compile argument: -use-network=false -debug=true
	public dynamic class SampleAdvanced extends MovieClip
	{
		private var temp:Object = {object1:{subObj:{text:"Some randome text", number:123}, subArr:[2, 3, 4, 5]}, object2:{arr:[3, 4, 5]}};

		public function SampleAdvanced()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			//
			// SET UP - only required once
			//
			Cc.start(this);
			// Cc.config.keystrokePassword = "`";
			// Cc.layer.mainPanel.visible = true; // show console, because having password hides console.
			// Cc.memoryMonitor = true;
			// Cc.fpsMonitor = true;
			// Cc.displayRoller = true;

			Cc.mainPanel.width = 700;
			Cc.mainPanel.height = 300;
			// Cc.config.remotingPassword = ""; // Just so that remote don't ask for password
			// Cc.remoting = true;
			/*
			Cc.addMenu("T1", Cc.log, ["Greetings 1"], "This is a test menu 1");
			Cc.addMenu("T2", Cc.log, ["Greetings 2"], "This is a test menu 2");
			Cc.addMenu("spam100k", spam, [100000]);*/
			//
			// End of setup
			//
			CLog.log("Lets try some object linking...");
			CLog.info("Here is a link to stage: ", stage);
			CLog.info("Here is a link to Cc class", Cc);
			CLog.info("Here is a link to Console instance", Cc);
			//
			// HTML text
			// CLog.addHTML("Here is HTML <font color='#ff00ff'>purple <b>bold</b> <b><i>and</i></b> <i>italic</i></font> text.");
			// CLog.addHTMLch("html", 8, "Mix objects inside html <p9>like this <i><b>&gt;", this,"&lt;</b></i></p9>");

			CLog.log("___");

			// explode an object into its values..
			// CLog.log("Cc.explode() test:");
			// Cc.explode(temp);

			CLog.log("___");
			CLog.info("Try the new search highlighting... Type '/filter link' in commandline below.");

			// CLog.stack("STACK TEST");
			// CLog.addEntry(new StackLogEntry(["TESTING!"]));
			//
			// Cc.addSlashCommand("test", function():void{ Cc.log("Do the test!");} );
			// Cc.addSlashCommand("test2", function(param:String):void{Cc.log("Do the test 2 with param string:", param);} );

			//
			// Graphing feature examples
			// Graph the current mouseX and mouseY values
			// Cc.addGraph("mouse", this,"mouseX", 0xff3333,"X", new Rectangle(560,180,80,80), true);
			// Cc.addGraph("mouse", this,"mouseY", 0x3333ff,"Y");
			// Sine wave graph generated by commandline execution, very expensive way to graph but it works :)
			// Cc.addGraph("mouse", this,"(Math.sin(flash.utils.getTimer()/1000)*300)+300", 0x119911,"sine");

			// Test of Cc.stack,  If you have debugger version installed you will see a stack trace like:
			// HELLO
			// @ SampleAdvanced/e()
			// @ SampleAdvanced/d()
			// @ SampleAdvanced/c()
			a();
			// see function e() below
		}

		private function a():void
		{
			b();
		}

		private function b():void
		{
			c();
		}

		private function c():void
		{
			d();
		}

		private function d():void
		{
			e();
		}

		private function e():void
		{
			// CLog.stack("Hello from stack trace.");
		}

		private function spam(chars:int):void
		{
			var str:String = "";
			while (str.length < chars)
			{
				str += "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
			}
			CLog.log(str.substring(0, chars));
			CLog.log("<<", chars, "chars.");
		}
	}
}
